package com.example.w.web.controller;

import com.example.w.common.pojo.Payment;
import com.example.w.common.util.Result;
import com.example.w.service.PaymentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payment")
@Api(tags = "支付接口")
public class PaymentController {

    @Autowired
    PaymentService paymentService;

    /**
     * 选择相关订单，和支付方式，调用接口支付
     * @param orderId 订单id
     * @param paymentType 支付方式，0：现金，1：微信，2：支付宝，3：银行卡
     * @return 支付结果
     */
    @GetMapping("/pay")
    @ApiOperation("支付订单，支付方式，0：现金，1：微信，2：支付宝，3：银行卡")
    public Result pay(@RequestParam Long orderId, @RequestParam int paymentType) {
        Payment target = paymentService.pay(orderId, paymentType);
        return new Result(true, "支付完成", target);
    }
}
